﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DataLayer.Entities;
using DonutMgmtSystemFoundation.App_Start;
using DonutMgmtSystemFoundation.Helpers;
using DonutMgmtSystemFoundation.Models;
using DonutMgmtSystemFoundation.Models.JqGridModel;

namespace DonutMgmtSystemFoundation.Controllers
{
    [AutorizeRole(Permission="Administrator")]
    public class AdminController : BaseController
    {
        public ActionResult ChangeSettings()
        {
            return View();
        }

        #region Donut catalog
        [HttpPost]
        public JsonResult UpdateDonutCatalog()
        {
            AdminHelper helper = new AdminHelper();

            return Json(helper.UpdateDonutsCatalog());
        }
        #endregion

        #region User's activation
        public ActionResult ActivateUsers()
        {
            AdminHelper helper = new AdminHelper();

            return View(helper.GetActivationUsers());
        }

        [HttpPost]
        public JsonResult SaveActivation(int userId)
        {
            AdminHelper helper = new AdminHelper();

            return Json(helper.ActivateUser(userId));
        }

        [HttpPost]
        public JsonResult SaveDeactivation(int userId)
        {
            AdminHelper helper = new AdminHelper();

            return Json(helper.DeactivateUser(userId));
        }
        #endregion

        #region Members management

        public ActionResult Members()
        {
            return View();
        }

        [HttpPost]
        public JsonResult GetMembers(JqGridRequest request)
        {
            AdminHelper helper = new AdminHelper();

            return Json(helper.GetMembers(request));
        }

        [HttpPost]
        public JsonResult EditMember(User user, int id, int Role)
        {
            AdminHelper helper = new AdminHelper();

            return Json(helper.SaveMember(user, id, Role));
        }

        #endregion

        #region SendMails

        public ActionResult SendMails()
        {
            AdminHelper helper = new AdminHelper();
            
            return View(helper.GetDefaultMailModels());
        }

        [HttpPost]
        public JsonResult SendOrderMail(MailModel model)
        {
            AdminHelper helper = new AdminHelper();

            return Json(helper.SendOrderMail(model));
        }

        [HttpPost]
        public JsonResult SendPaymentMail(MailModel model)
        {
            AdminHelper helper = new AdminHelper();

            return Json(helper.SendPaymentMail(model));
        }

        [HttpPost]
        public JsonResult SendDonutsArrivedMail(MailModel model)
        {
            AdminHelper helper = new AdminHelper();

            return Json(helper.SendDonutsArrivedMail(model));
        }

        #endregion
    }
}
